﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using EHR.Common;

namespace CommunitySystem.PageView
{
    public partial class CheGaiWindow : ChildWindow
    {
        private EmpbasicService.EmpBasicServiceClient Client = new EmpbasicService.EmpBasicServiceClient();
        private EmpbasicService.CheGaiModel model = new EmpbasicService.CheGaiModel();
        public int ID;
        public CheGaiWindow(int iD)
        {
            InitializeComponent();
            ID = iD;

            this.Title = "编辑车改信息";
            Client.GetOneCheGaiCompleted += new EventHandler<EmpbasicService.GetOneCheGaiCompletedEventArgs>(Client_GetOneCheGaiCompleted);
            Client.GetOneCheGaiAsync(ID);

        }

        void Client_GetOneCheGaiCompleted(object sender, EmpbasicService.GetOneCheGaiCompletedEventArgs e)
        {
            if (e.Result != null)
            {
                model = e.Result;
            }
            this.DataContext = model;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            model.Operator = Session.LoginUser.LoginName;
            model.CreateDate = DateTime.Today;
            Client.UpdateCheGaiCompleted += new EventHandler<EmpbasicService.UpdateCheGaiCompletedEventArgs>(Client_UpdateCheGaiCompleted);
            Client.UpdateCheGaiAsync(model);
        }

        void Client_UpdateCheGaiCompleted(object sender, EmpbasicService.UpdateCheGaiCompletedEventArgs e)
        {
            if (e.Result == true)
            {
                SilverlightMessageBoxLibrary.Message.InfoMessage("编辑成功！");
                this.DialogResult = true;
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void DictTextBox_OnSelectionChanged(object sender, object NewValue, object OldValue)
        {

        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                double.Parse(((TextBox)sender).Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                ((TextBox)sender).Text = "";
            }
        }
    }
}
